package com.sudichina.sudichina.view.activity.main;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.ImageView;

import com.sudichina.sudichina.R;
import com.sudichina.sudichina.utils.ActivityFinishUtils;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by 杨伟乔
 */
public class SplashActivity extends AppCompatActivity implements Animation.AnimationListener {
    public static final String FIRST_OPEN = "first_open";
    //动画
    private AlphaAnimation animation;

    @BindView(R.id.splash)
    ImageView splash;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_splash);
        ButterKnife.bind(this);
        //初始化动画
        initAnimation();
        //初始化监听
        initListener();

        ActivityFinishUtils.addActivity(this);


    }


    //初始化动画
    private void initAnimation() {

//创建动画 渐变动画
        animation = new AlphaAnimation(0.5f, 1.0f);
        //设置时间
        animation.setDuration(2000);
        //开启动画
        splash.startAnimation(animation);

    }

    //初始化监听
    private void initListener() {

        animation.setAnimationListener(this);

    }



    //动画开始
    @Override
    public void onAnimationStart(Animation animation) {

    }

    //动画结束
    @Override
    public void onAnimationEnd(Animation animation) {
        enterActivity();
    }

    @Override
    public void onAnimationRepeat(Animation animation) {

    }


    private void enterActivity() {

////判断用户是否是第一次进入程序 如果是第一次进入 进入引导界面
//         boolean firstOpen = (boolean) SpUtils.getBoolean(this,Contains.IS_FRIST,false);
//
//       if (firstOpen) {
//            intent =
//                     new Intent(SplashActivity.this,
//                           WelcomeGuideActivity.class);
//
//        }else {
//           //如果不是第一次进入 就进入到主界面
//           intent =
//                   new Intent(SplashActivity.this, MainActivity1.class);
//
//       }
        Intent intent =
                   new Intent(SplashActivity.this, MainActivity.class);
        startActivity(intent);



        finish();

    }
}
